<script type="text/javascript">
	$("li#menu2").addClass("current");
</script>
<form action="" method="post">
	<table>
		<tr>
			<td>Filtrer par cat&eacute;gories:</td>
			<td>
				<select name="category">
					<option value="0"> Toutes</option>
				<?php
				
					foreach($mainCategories as $mainCat)
					{
						if(isset( $_POST['category']) && $_POST['category'] ==$mainCat->getIdCat())
							echo "<option value='".$mainCat->getIdCat()."' selected='selected'>".$mainCat->getNameCat()."</option>";
						else
							echo "<option value='".$mainCat->getIdCat()."'  >".$mainCat->getNameCat()."</option>";
						
						$subcategories = Category::listing("WHERE CAT_IdParent = ".$mainCat->getIdCat());
						
						foreach($subcategories as $subCat)
						{
							if(isset( $_POST['category']) && $_POST['category'] ==$subCat->getIdCat())
								echo "<option value='".$subCat->getIdCat()."' selected='selected'>----".$subCat->getNameCat()."</option>";
							else
								echo "<option value='".$subCat->getIdCat()."' >----".$subCat->getNameCat()."</option>";
						}
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td>Filtrer par statuts:</td>
			<td>
				<select name="status">
					<option value="0"> Tous</option>
				<?php
					foreach($status as $stat)
					{
						if(isset( $_POST['status']) && $_POST['status'] == $stat->getIdStatus())
							echo "<option value='".$stat->getIdStatus()."' selected='selected'>".$stat->getNameStatus()."</option>";
						else
							echo "<option value='".$stat->getIdStatus()."'>".$stat->getNameStatus()."</option>";
					}
				?>
				</select>
			</td>
		</tr>
		<tr>
			<td><input type="submit" value="Filtrer"/></td>

	</table>	
</form>


	<form action="?page=article.php" method="post">
		<input type="submit" value="Nouvel article">
	</form>

	
<?php


if(null !== $articlesList[0])
{
	foreach($articlesList as $article)
	{
		$author=User::read($article->getIdPublisherArt())
		 ?>
		<table>	
		<tr>
			<td>
			  <?php echo "<a href='?page=article.php&amp;idArt=".$article->getIdArt()."&amp;action=edit'>". $article->getTitleArt()."</a>";?>
			</td>
			<td>
			  <?php 
			  list($annee, $mois, $jour) = explode('-', $article->getDateArt());
			  $semaine = date("w", mktime(0, 0, 0, $mois, $jour, $annee));
			  echo date_fran($jour, $mois, $annee, $semaine);
			  ?>
			</td>
			<td>
				<?php
						echo $author->getFirstNameUser();
						
						?>
			</td>
			<td>
			  <?php echo "<a href='?page=article.php&amp;idArt=".$article->getIdArt()."&amp;action=suppr'>Supprimer</a>";?>
			</td>
		</tr>
		  </table> 
	  <?php
			
	}
}
else
	echo "Oups ! Il semblerait qu'il n'y est pas d'article.";
	//Pagination
	// if(isset($nbPages) && $pagination)
	// {
		// for($i=1; $i<=$nbPages; $i++)
			// echo "<a href='#&numPageArt=$i'>$i</a>";
	// }	

 ?>

		